/**
 * Created by hda on 2017/5/20.
 */
define(['jquery', 'vue', 'ks-spa'], function ($, Vue,spa) {
    var $list_data = document.getElementById('list_data').value;

    var vue = gvue = new Vue({
        el: "#el-address-select",
        data: {
            list: eval($list_data),
            address_id: 0
        },
        methods: {
            edit: function (id) {
                // console.log(id);
                this.rebind();
            },
            del: function (id) {
                mui.confirm('确定删除地址？','',['取消','确定'],function (e) {
                    if(e.index==1){

                        $.post(root_path + '/user/address/delete', {id: id}, function (json) {
                            mui.toast(json.msg);
                            if (json.flag) {
                                // $(event.currentTarget).parents('ul').remove()
                                $("#ul_address_" + id).remove();
                                if (typeof (json.address) != 'undefined') {
                                    $("#ul_address_" + json.address.id).addClass('active');

                                    $("#address_id").val(json.address.id);
                                    $("#address_name").html(json.address.name);
                                    $("#address_mobile").html(json.address.mobile);
                                    var $address = json.address.province + ' ' + json.address.city + ' ' + json.address.district + ' ' + json.address.address;
                                    $("#address_address").html($address);

                                }
                            }
                        })



                    }
                })



            },
            choose: function (m) {
                $(event.currentTarget.parentNode.parentNode.children).removeClass('active');
                event.currentTarget.parentNode.className = 'active';
                $("#address_id").val(m.id);
                $("#address_name").html(m.name);
                $("#address_mobile").html(m.mobile);
                var $address = m.province + ' ' + m.city + ' ' + m.district + ' ' + m.address;
                $("#address_address").html($address);
                get_dispatch_money(m.id);
                spa.close('addressSelect');
               // history.back();
            },
            rebind: function () {
                vue.list={};
                $.get(root_path + '/user/address/select_data', function (json) {
                    vue.list = json;
                })
            }
        },
        mounted: function () {
            this.address_id = $("#address_id").val();
        }
    })
})